<?php
/**
* 用户购物地址管理
*/
namespace V3\Controller;

use Think\Controller; 
use Think\Vender;

class WxpayController extends ApiCommonController{
	
	 
	//获取全部地址
	public function test(){
		$return_data = array(
			'status'	=>	'1',
			'info'	=>	'结果为空',
			'data'	=>	array(
				'username'	=>	'张三'
			),	
		); 
		$this->ajaxReturn($return_data);
	}
	
	public function getParm(){
		Vendor("Pay.Wxpay.WxPayHelper"); 
		
		$orderBody = '商品详情信息';
		$tade_no = date('YmdHis').'_'.mt_rand(1000,9999);
		$total_fee = 1;
		
		$WxPayHelper = new \WxPayHelper();
		$response = $WxPayHelper->getPrePayOrder($orderBody, $tade_no, $total_fee);
		$data = $WxPayHelper->getOrder($response['prepay_id']);
 
		//兼容前端为空出问题的情况
		$return_data = array(
			'status'	=>	'1',
			'info'	=>	'参数获取成功',
			'data'	=>	$data,
		);
		
		$this->ajaxReturn($return_data);
		 
	}

	public function notify(){
		Vendor("Pay.Wxpay.WxPayHelper");
		$WxPayHelper = new \WxPayHelper();
		$data = array(
			'post' =>	$_POST,
			'get' =>	$_GET,
			'file' =>	$_FILES,
			'xml'	=> file_get_contents("php://input"),
		);
		$data['xml'] = $WxPayHelper->xmlstr_to_array($data['xml']);
		$this->_log($data);
	}
	
	public function _log($data){
		$str = $this->_tostring($data);
		$str = date('Y-m-d H:i:s',time()).'|'.$str.'
';
		$f = fopen('/home/mov30.weixinzjit.com/Public/log/log.txt','a+');
		fwrite($f,$str);
		fclose($f);
	}
	
	public function _tostring($obj){
		if(is_string($obj)) return $obj;
		return json_encode($obj);
	}
}